part of '../repository.dart';

class _PurchasedSubscriptionInfoCancellationInfoDtoFactory {
  const _PurchasedSubscriptionInfoCancellationInfoDtoFactory._internal();

  static const _instance = _PurchasedSubscriptionInfoCancellationInfoDtoFactory._internal();

  factory _PurchasedSubscriptionInfoCancellationInfoDtoFactory() {
    return _instance;
  }

  _PurchasedSubscriptionInfoCancellationInfoDto fromJson(Map<String, dynamic> json) {
    final type = json[_kPurchasedSubscriptionInfoCancellationInfoTypeKey] as String;

    if (type == _kPurchasedSubscriptionInfoUserCancellationInfoTypeValue) {
      return _PurchasedSubscriptionInfoUserCancellationInfoDto.fromJson(json);
    }

    if (type == _kPurchasedSubscriptionInfoSystemCancellationInfoTypeValue) {
      return const _PurchasedSubscriptionInfoSystemCancellationInfoDto();
    }

    if (type == _kPurchasedSubscriptionInfoDeveloperCancellationInfoTypeValue) {
      return const _PurchasedSubscriptionInfoDeveloperCancellationInfoDto();
    }

    if (type == _kPurchasedSubscriptionInfoNewSubscriptionCancellationInfoTypeValue) {
      return const _PurchasedSubscriptionInfoNewSubscriptionCancellationInfoDto();
    }

    throw UnimplementedError();
  }

  _PurchasedSubscriptionInfoCancellationInfoDto fromEntity(
      GooglePlayPurchasedSubscriptionInfoCancellationInfo cancellationInfo) {
    if (cancellationInfo is GooglePlayPurchasedSubscriptionInfoUserCancellationInfo) {
      return _PurchasedSubscriptionInfoUserCancellationInfoDto.fromEntity(cancellationInfo);
    }

    if (cancellationInfo is GooglePlayPurchasedSubscriptionInfoSystemCancellationInfo) {
      return const _PurchasedSubscriptionInfoSystemCancellationInfoDto();
    }

    if (cancellationInfo is GooglePlayPurchasedSubscriptionInfoDeveloperCancellationInfo) {
      return const _PurchasedSubscriptionInfoDeveloperCancellationInfoDto();
    }

    if (cancellationInfo is GooglePlayPurchasedSubscriptionInfoNewSubscriptionCancellationInfo) {
      return const _PurchasedSubscriptionInfoNewSubscriptionCancellationInfoDto();
    }

    throw UnimplementedError();
  }
}
